﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page 
{

    private int chanel_id = Helper.getQuery("cid");
    PanelBusiness panel = new PanelBusiness();
    ChanelBusiness channel = new ChanelBusiness();
    private string url = Helper.getQuerystr("url");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (chanel_id == 0)
            {
                System.Collections.ArrayList items = channel.Menu();
                ChannelesEntities c = null;
                if (items != null && items.Count > 0)
                {
                    c = (ChannelesEntities)items[0];
                }
                if (c != null)
                {
                    chanel_id = c._id;
                }
            }

            if (url != null && !url.Equals(""))
            {
                PanelControl p = (PanelControl)LoadControl(url);
                p.ID = Helper.getQuery("pid");
                this.center.Controls.Add(p);
            }

            bool cell1 = false, cell2 = false, cell3 = false, cell4 = false, cell5 = false,cell6 = false,
                cell7 = false, cell8 = false, cell9 = false, cell10 = false, cell11 = false, cell12 = false;

            System.Collections.ArrayList item_all = panel.getPanel_All();
            if (item_all != null)
            {
                PanelesEntities item = null;
                for (int i = 0; i < item_all.Count; i++)
                {
                    item = (PanelesEntities)item_all[i];
                    PanelControl pn = (PanelControl)LoadControl("Panel.ascx");
                    pn.ID = item._id;
                    switch (item._cellID)
                    {
                        case 1:
                            this.logo1.Controls.Add(pn);
                            cell1 = true;
                            break;
                        case 2:
                            this.menu.Controls.Add(pn);
                            cell2 = true;
                            break;
                        case 3:
                            this.slide.Controls.Add(pn);
                            cell3 = true;
                            break;
                        case 4:
                            this.cate.Controls.Add(pn);
                            cell4 = true;
                            break;
                        case 5:
                            this.news.Controls.Add(pn);
                            cell5 = true;
                            break;
                        case 6: if (url == null || url.Equals(""))
                            {
                                this.view1.Controls.Add(pn);
                                cell6 = true;                               
                            }
                            break;
                        case 7: if (url == null || url.Equals(""))
                            {
                                this.view2.Controls.Add(pn);
                                cell7 = true;
                            }
                            break;
                        case 8: if (url == null || url.Equals(""))
                            {
                                this.view3.Controls.Add(pn);
                                cell8 = true;
                            }
                            break;
                        case 9:
                            this.online.Controls.Add(pn);
                            cell9 = true;
                            break;
                        case 10:
                            this.service.Controls.Add(pn);
                            cell10 = true;
                            break;
                        case 11:
                            this.footer.Controls.Add(pn);
                            cell11 = true;
                            break;
                        case 12:
                            this.logo.Controls.Add(pn);
                            cell12 = true;
                            break;
                    }
                }
            }
            System.Collections.ArrayList item_chanel = panel.getPanel_Chanel(chanel_id);

            if (item_chanel != null)
            {
                PanelesEntities item = null;
                for (int i = 0; i < item_chanel.Count; i++)
                {
                    item = (PanelesEntities)item_chanel[i];
                    PanelControl pn = (PanelControl)LoadControl("Panel.ascx");
                    pn.ID = item._id;
                    switch (item._cellID)
                    {
                        case 1:
                            if(!cell1)
                            this.logo1.Controls.Add(pn);
                            break;
                        case 2:
                            if(!cell2)
                            this.menu.Controls.Add(pn);
                            break;
                        case 3:
                            if(!cell3)
                            this.slide.Controls.Add(pn);
                            break;
                        case 4:
                            if(!cell4)
                            this.cate.Controls.Add(pn);
                            break;
                        case 5:
                            if(!cell5)
                            this.news.Controls.Add(pn);
                            break;
                        case 6: if ((url == null || url.Equals(""))&&(!cell6))
                            {
                                this.view1.Controls.Add(pn);
                            }
                            break;
                        case 7: if ((url == null || url.Equals(""))&&(!cell7))
                            {
                                this.view2.Controls.Add(pn);
                            }
                            break;
                        case 8: if ((url == null || url.Equals(""))&&(!cell8))
                            {
                                this.view3.Controls.Add(pn);
                            }
                            break;
                        case 9:
                            if(!cell9)
                            this.online.Controls.Add(pn);
                            break;
                        case 10:
                            if(!cell10)
                            this.service.Controls.Add(pn);
                            break;
                        case 11:
                            if(!cell11)
                            this.footer.Controls.Add(pn);
                            break;
                        case 12:
                            if(!cell12)
                            this.logo.Controls.Add(pn);
                            break;
                    }
                }
            }
        }

    }


}
